//package com.park.interceptor;
//
//import com.alibaba.fastjson.JSON;
//import com.park.common.CommonResult;
//import com.park.util.JWTUtil;
//import org.apache.tomcat.util.http.parser.Authorization;
//import org.springframework.stereotype.Component;
//import org.springframework.web.servlet.HandlerInterceptor;
//import org.springframework.web.servlet.ModelAndView;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//@Component
//public class LoginInterceptor implements HandlerInterceptor {
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        //在处理handler之前执行
//        // 如果返回true，那么就可以执行对应的handler。返回false，执行不到handler
//        //return true/false是springmvc中的运行路线需求，不是回应浏览器的
//
//        //验证每个请求是否是登陆状态
//
//        //怎样就是登录状态？  有token，token有效
//
//        //token在哪？  在headers中，叫做Authorization
//        String token=request.getHeader("Authorization");
//        if(token!=null&& JWTUtil.verifyToken(token)){
//            //有token，token有效，有登录状态
//            return true;
//        }else {
//            System.out.println("触发了拦截器");
//            //要回应的数据
//            CommonResult result=CommonResult.fail(400,"Password has not been changed yet");
//            //将数据解析成json
//            String json= JSON.toJSONString(result);
//            //将数据回应
//            response.getWriter().write(json);
//            return false;
//        }
//
//    }
//
//    @Override
//    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
//        HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
//    }
//
//    @Override
//    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
//        HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
//    }
//}
